<template>
    <div class="all">
        <table>
            <thead>
                <tr>
                    <td><el-checkbox v-model="checkAll"></el-checkbox>
                    全选</td>
                    <td>商品信息</td>
                    <td>单价</td>
                    <td>数量</td>
                    <td>小计</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in list" :key="item.id">
                    <td><el-checkbox v-model="item.checked"></el-checkbox></td>
                    <td class="desc">
                        <div class="img"><img src="" alt=""></div>
                        <div>
                            <div>日本骄测试服短时就的数据</div>
                            <div class="ss"></div>
                            <div class="xianshi"><i class="el-icon-arrow-down"></i></div>
                        </div>
                    </td>
                    <td>￥{{ item.price }}</td>
                    <td><el-input-number v-model="item.count" @change="handleChange(item)" :min="1" :max="10"
                            label="描述文字"></el-input-number>
                    </td>
                    <td class="red">￥{{ item.price * item.count }}</td>
                    <td>
                        <div>移入收藏夹</div>
                        <div class="green" @click="del(item)">删除</div>
                        <div>找相似</div>
                    </td>
                </tr>
                <tr>
                    <td colspan="5">
                        <div>{{ totalPrice }}</div>---<div>{{ num }}</div>
                        <div>下单结算</div>
                    </td>
                </tr>
            </tbody>
        </table>
        <div>
            <div class="title">猜你喜欢</div>
            <el-carousel indicator-position="outside">
                <el-carousel-item v-for="item in s" class="allImg" :key="item.id">
                    <div class="c" v-for="item2 in item" :key="item2.id">
                        <img class="img" :src="item2.picture" alt="">
                        <div class="name">{{ item2.name }}</div>
                        <div class="price">{{ item2.price }}</div>
                    </div>
                </el-carousel-item>
            </el-carousel>
        </div>
    </div>
</template>

<script>
import { likes } from '@/request/api/wxy/wxy';
export default {
    data() {
        return {
            list: [
                {
                    id: 0,
                    checked: true,
                    name: "文档",
                    price: 100,
                    count: 10,
                    iPrice: 0
                },
                {
                    id: 1,
                    checked: false,
                    name: "哈哈",
                    price: 200,
                    count: 10,
                    iPrice: 0

                },
                {
                    id: 2,
                    checked: false,
                    name: "文档",
                    price: 300,
                    count: 10,
                    iPrice: 0

                }
            ],
            baner: [],
            s: []
        };
    },


    mounted() {
        this.likess(); // 调用 likess 方法
    },
    computed: {
        totalPrice() {
            let checkedGoods = this.list.filter(item => item.checked);
            let sum = checkedGoods.reduce((per, item) => {
                return per += item.price * item.count;
            }, 0);
            return sum;
        },
        num() {
            let sumN = this.list.reduce((per, item) => {
                return per += item.count;
            }, 0);
            return sumN
        },
        checkAll: {
            get() {//给checkAll赋值，如果如果小的是全选就为true那么总就是true为选中//给checkAll赋值
                let check = this.list.every(item => {
                    return item.checked == true
                })
                return check
            },
            set(val) {//这个是判断checkAll的改变如果总为true那么fen都为这个状态//监听checkAll的状态
                this.list.forEach(item => {
                    item.checked = val
                })
            }
        }

    },

    methods: {
        async likess() {
            const res = await likes();
            console.log("猜你喜欢", res);

            this.baner = res.data.result.items
            const chunkSize = 3; // 每个子数组的大小

            const resultArray = [];
            for (let i = 0; i < this.baner.length; i += chunkSize) {
                resultArray.push(this.baner.slice(i, i + chunkSize));
            }
            this.s = resultArray
            console.log(resultArray);
        },
        handleChange(item) {
            console.log(item);

        },
        del(item) {
            console.log("11")

            if (item.checked) {
                const index = this.list.findIndex(goodsItem => goodsItem.id === item.id);
                if (index !== -1) {
                    this.list.splice(index, 1);
                }
            }
        }
    }

}
</script>

<style lang="scss" scoped>
input{
    width: 20px;
    height: 20px;
    color: #73d1e1;
    border: 1px solid blue;
}
:deep(.el-carousel__button) {
    width: 15px;
    height: 15px;
    border-radius: 50%;
}


:deep(.el-carousel__indicators) {
    position: absolute;
    bottom: 5px;
}

:deep( .el-carousel__indicator--horizontal.is-active .el-carousel__button ){
    background-color: #73d1e1;
}

.title {
    padding-left: 20px;
    height: 80px;
    font-size: 25px;
    line-height: 80px;

}

.allImg {
    display: flex;
    align-items: center;
    justify-content: space-around;

    .c {
        position: relative;
        height: 289px;

        .img {
            width: 230px;
            display: block;
            height: 220px;
        }

        .name {
            width: 230px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        .price {
            text-align: center;
        }
    }
}

.el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
}

.all {
    // background-color: #fff;
    width: 100vw;

    table {
        width: 750px;
        margin: 10px auto;
        font-size: 13px;

        tr {
            box-sizing: border-box;
            padding-left: 10px;

            td {
                padding: 10px;
            }
        }

        thead {
            tr {
                td {
                    text-align: center;
                }
            }
        }

        .desc {
            display: flex;
            width: 240px;
            align-items: center;
            height: 70px;

            .img {
                width: 60px;
                height: 60px;

                img {
                    width: 60px;
                    height: 60px;
                }

            }
        }

        .green {
            color: #73d1e1;
        }

        .red {
            background-color: red;
        }
    }
}
</style>